//1. 引入mysql
const mysql = require('mysql2')
//2. 创建mysql连接对象
const connection = mysql.createConnection({
	host: 'localhost', // 数据库服务端地址
	database: 'goodsdb2301', //数据库名
	user: 'root',
	password: 'b123',
})

//3. 建立数据库连接
connection.connect()

//4.执行sql语句
const sql = "INSERT INTO users (username,password,age)VALUES('admin','123',18)"
connection.query(sql, function (err, results) {
	if (err) {
		console.log('数据库操作失败', err)
		return
	}
	console.log(results)
})

//5.关闭数据库
connection.end()
